package com.album.activity.pageView;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;



import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemLongClickListener;

import com.album.R;
import com.album.activity.MessageDialog;
import com.album.activity.SetstateManager; 
import com.album.activity.adapter.MyPhotoAdapter;
import com.album.activity.page.Page;
import com.album.activity.page.PageManager;
import com.album.bean.ErrorInfo;
import com.album.bean.PicinfoList;
import com.album.bean.RondomUser;
import com.album.http.HttpRequest;
import com.album.task.AddFriendTask;
import com.album.task.DownImageTask;
import com.album.task.GetPicinfolistTask;
import com.album.task.GetRandomPicinfolistTask;
import com.album.task.GetUsersRandom;
import com.album.task.ICallBack;
import com.album.task.Task;
import com.album.utils.AndroidUtils;
import com.album.utils.CommonUtil;
import com.album.utils.Config;
import com.album.utils.MyLog;
import com.album.utils.down.AsyncImageLoader;
import com.album.utils.down.MyImageAdapter;
import com.album.utils.down.ImageAndText;
import com.album.utils.down.AsyncImageLoader.ImageCallback;
import com.album.utils.down.ImageAndTextListAdapter;
import com.google.gson.Gson;

public class CasualLookView extends Page{
	private static String TAG = "CasualLookView";
	 /** 
     * 文件夹下的图片列表 
     */  
	private List<Integer> mImageList;
	private List<Integer> mImageList2;
	/**
	 * 好友头像
	 */
	private List<Integer> myFriendsList;
	private ListView casualListView;
	private HorizontalScrollView scrollView;
	private Gson gson;

	private static final int HENDLER = 110;
	private static final int ROMDOMUSER_INFO = 111;
	private static final int ROMDOMUSER_FAIL = 112;
	private static final int ROMDOMUSER_IMAGE_INFO = 113;
	private static final int ROMDOMUSER_IMAGE_FAIL = 114;
	private static final int ROMDOMUSER_NO = 115;
	private static final int PICINFOLIST_RE_MYPTO_IMAGE = 117;
	private static final int PICINFOLIST_DOWN_IMAGE_FAIL = 118;
	private static final int PICINFOLIST_INFO = 119;
	private static final int PICINFOLIST_INFO_FAIL = 200;
	
	private static final int ADD_FRIENDS = 201;
	private static final int ADD_FRIENDS_FAIL = 202;

	private static final int TIME_OUT = 11;
	private static final int INTENT_ERROR = 12;
	private static final int HTTP_ERROR = 13;
	private ProgressDialog dialog_1;
	private Context ctx;
	/*
	 * 存放用户头像、昵称、时间、相片
	 */
	private List<RondomUser> userRanList = new ArrayList<RondomUser>();
	private ListAdapter adapterTest;
	
	public CasualLookView(PageManager manager) {
		super(manager);
	}
	@Override
	public View getView() {
		Log.i(TAG, "@Override getView");
		return casualListView;
	}
	@Override
	public void onCreate(Object extra) {
		super.onCreate(extra);
		Log.i(TAG, "onCreate");
		if(userRanList != null && userRanList.size()>0){
			userRanList.clear();
		}
		
		MyLog.info(CasualLookView.class, "onCreate()");
		ctx = manager.getContext();
		SetstateManager.setBacktoState(CasualLookView.class,manager);
		SetstateManager.setRefresState(CasualLookView.class,manager);
		casualListView = new ListView(ctx);
		casualListView.setBackgroundColor(Color.BLACK);
		casualListView.setCacheColorHint(0x00000000);
		casualListView.setScrollbarFadingEnabled(false);
		casualListView.setVerticalScrollBarEnabled(true);

		mImageList = new ArrayList<Integer>();
		mImageList2 = new ArrayList<Integer>();
		myFriendsList = new ArrayList<Integer>();

		myFriendsList.add(R.drawable.icon);
		myFriendsList.add(R.drawable.icon);
		mImageList.add(R.drawable.liu);
		mImageList.add(R.drawable.liu);
		mImageList.add(R.drawable.liu);
		mImageList.add(R.drawable.liu);
		SetstateManager.setPicListState("",mImageList);
		mImageList2.add(R.drawable.icon);
		mImageList2.add(R.drawable.icon);
		mImageList2.add(R.drawable.icon);
		mImageList2.add(R.drawable.icon);
		
		adapterTest = new ListAdapter(manager.getContext());
	    casualListView.setAdapter(adapterTest);
	    
       //随机获取好友列表
	    
        getRandomFriends();
//		List<String> imageList = new ArrayList<String>();
//		adapterTest = new ListAdapter(manager.getContext());
//	    casualListView.setAdapter(adapterTest);
	}
	/**
	 * 获取好友列表
	 * @author Administrator
	 */
	private String getRandomFriends(){
		String rspString = null;
		if(gson == null)
		  gson = new Gson();
		Task task = new GetUsersRandom(ctx,new ICallBack() {
			@Override
			public void CallBack(String imageUrl, Bitmap bm) {
			}
			@Override
			public void CallBack(String rspString) {
				try {
					MyLog.info(getClass(), "jsonData:" + rspString);
					rspString = "[" + rspString + "]";
					JSONArray array = new JSONArray(rspString.toString());
					JSONArray array_data;
					JSONObject obj = array.getJSONObject(0);
					if (obj.getBoolean("msg")) {
						String res_data = obj.getString("data");
						MyLog.info(getClass(),
								"data:" + res_data.toString());
						if("[]".equals(res_data.toString())){
							handler.sendEmptyMessage(ROMDOMUSER_NO);
							return;
						}
						array_data = new JSONArray(res_data.toString());
						for (int i = 0; i < array_data.length(); i++) {
							RondomUser user = new RondomUser();
							JSONObject obj_data = array_data.getJSONObject(i);
							user.setPassport(obj_data.getString("passport"));
							user.setNick(obj_data.getString("nick"));
							user.setHead_path(obj_data.getString("icon"));
							userRanList.add(user);
							Bitmap bm = getBitmap(user);
							
							Message heandms = new Message();
							heandms.obj=bm;
							heandms.what = HENDLER;
							handler.sendMessage(heandms);
							Message ms = new Message();
							ms.obj=user;
							ms.what = ROMDOMUSER_INFO;
							handler.sendMessage(ms);
						}
					} else {
						RondomUser info=new RondomUser();
						info.setErrCode(obj.getString("errCode"));
						Message ms = new Message();
						ms.what = ROMDOMUSER_FAIL;
						ms.obj = info;
						handler.sendMessage(ms);
					}
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

			}
			@Override
			public void TimeOut() {
				// TODO Auto-generated method stub
				handler.sendEmptyMessage(TIME_OUT);
			}
			@Override
			public void HttpError(int errorCode) {
				// TODO Auto-generated method stub
				handler.sendEmptyMessage(INTENT_ERROR);
			}
		});
		dialog_1 = ProgressDialog.show(ctx, "",ctx.getText(R.string.get_random_frineds), true);
		dialog_1.setCancelable(true);
		task.doTask(task);
		return rspString;
	}
	/**
	 * 获取相册列表
	 */
	private void getPicinfolist(final String username) {
		MyLog.info(getClass(), "getPicinfolist username:"+username);
		if (gson == null) {
			gson = new Gson();
		}
		Task task = new GetRandomPicinfolistTask(ctx,username, null,
				new ICallBack() {
					@Override
					public void CallBack(String imageUrl, Bitmap bm) {
					}
					@Override
					public void CallBack(String rspString) {
						// TODO Auto-generated method stub
						MyLog.info(getClass(), "jsonData:" + rspString);
						rspString = "[" + rspString + "]";
						JSONArray array;
						JSONArray array_data;
						List<PicinfoList> picinfoList;
						List<String> imangeList;
						try {
							picinfoList = new ArrayList<PicinfoList>();
							imangeList = new ArrayList<String>();
							array = new JSONArray(rspString.toString());
							JSONObject obj = array.getJSONObject(0);
							if (obj.getBoolean("msg")) {
								String res_data = obj.getString("data");
								MyLog.info(getClass(),
										"data:" + res_data.toString());
								array_data = new JSONArray(res_data.toString());
								for (int i = 0; i < array_data.length(); i++) {
									JSONObject obj_data = array_data.getJSONObject(i);
									MyLog.info(getClass(),"exif:" + obj_data.toString());
									PicinfoList info = new PicinfoList();
//									info.setFileid(obj_data.getString("fileid"));
									info.setId(obj_data.getString("id"));
									info.setPassport(obj_data.getString("passport"));
//									info.setPublic_(obj_data.getString("public"));
//									info.setTypeid(obj_data.getString("typeid"));
									info.setUpload_time(obj_data.getString("upload_time"));
//									info.setTitle(obj_data.getString("title"));
//									info.setContent(obj_data.getString("content"));
//									info.setViews(obj_data.getString("views"));
//									info.setScore(obj_data.getString("score"));
//									info.setBlock(obj_data.getString("block"));
//									info.setArea(obj_data.getString("area"));
//									info.setCoordinate(obj_data.getString("coordinate"));
									info.setPath_image(obj_data.getString("web_path"));
//									info.setHash_code(obj_data.getString("hash_code"));
									MyLog.info(getClass(),
											"web_path:" + info.getPath_image());
									//ProviderUtil.insertOrUpdatePicinfoList(manager.getContext(), info);
									picinfoList.add(info);
									if(info.getPath_image()!=null){
									String imageUrul = Config.TyDownHttp+info.getPassport()+"/"+info.getPath_image().substring(info.getPath_image().lastIndexOf("/")+1);
									MyLog.info(getClass(),
											"random imageUrul:" + imageUrul);
									imangeList.add(imageUrul);
									Message ms = new Message ();
									ms.what = PICINFOLIST_INFO;
									ms.obj =  imageUrul;
									handler.sendMessage(ms);
									}
								} 
								
							} else {
								PicinfoList info = new PicinfoList();
								info.setErrCode(obj.getString("errCode"));
								Message ms = new Message ();
								ms.what = PICINFOLIST_INFO_FAIL;
								ms.obj = info;
								handler.sendMessage(ms);
							}
							
						} catch (JSONException e) {
							e.printStackTrace();
						}
					}
					@Override
					public void TimeOut() {
						//网络超时处理
						handler.sendEmptyMessage(TIME_OUT);
					}
					@Override
					public void HttpError(int errorCode) {
						// TODO Auto-generated method stub
						handler.sendEmptyMessage(INTENT_ERROR);
					}
				});
		task.doTask(task);
	}
	/**
	 * 下载图片
	 * @param filenameList
	 */
    private void downMyPtoImage(List<String> filenameList,final String username){
    	final List<Bitmap> piclist = new ArrayList<Bitmap>();
    	Task task = new DownImageTask(manager.getContext(), username, filenameList, new ICallBack() {
			@Override
			public void CallBack(String imageUrl, Bitmap bm) {
				//发handler 做刷新操作
				MyLog.info(getClass(), "image bm:"+bm);
				if(bm != null){	
			    piclist.add(bm);
				//SetstateManager.setPicMapState(username,piclist);//添加到状态机制 供查看单张图片
				Message ms = new Message();
				ms.what = PICINFOLIST_RE_MYPTO_IMAGE;
				ms.obj = bm;
				handler.sendMessage(ms);
				}else{
					Message ms = new Message();
					ms.what = PICINFOLIST_DOWN_IMAGE_FAIL;
				    handler.sendMessage(ms);
				}
			}
			@Override
			public void CallBack(String rspString) {
			}
			@Override
			public void TimeOut() {
				// TODO Auto-generated method stub
			}
			@Override
			public void HttpError(int errorCode) {
				// TODO Auto-generated method stub
				handler.sendEmptyMessage(TIME_OUT);
			}
		});
    	task.doTask(task);
    }
    
    
    /**
     * 添加好友
     * @author Administrator
     *
     */
	private void addFriend(String friendname){
		Task task = new AddFriendTask(ctx,CommonUtil.getUserName(ctx),friendname,new ICallBack() {
			
			@Override
			public void TimeOut() {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void HttpError(int errorCode) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void CallBack(String imageUrl, Bitmap bm) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void CallBack(String rspString) {
				try {
					MyLog.info(getClass(), "jsonData:" + rspString);
					rspString = "[" + rspString + "]";
					JSONArray array = new JSONArray(rspString.toString());
					JSONObject obj = array.getJSONObject(0);
					if (obj.getBoolean("msg")) {
						Message ms = new Message();
						ms.what = ADD_FRIENDS;
						handler.sendMessage(ms);
					} else {
						Message ms = new Message();
						ms.what = ADD_FRIENDS_FAIL;
						handler.sendMessage(ms);
					}
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			}
		});
		task.doTask(task);
	}
    /**
     * 处理ui界面
     */
    private Handler handler = new Handler() {
		public void handleMessage(Message msg) {
			try {
				switch (msg.what) {
				case HENDLER:
					Bitmap bitmap = (Bitmap)msg.obj;
					adapterTest.setDataSetChangedBitmap(bitmap);
					break;
				case ROMDOMUSER_INFO:
					RondomUser user=(RondomUser)msg.obj;
//					if(userRanList != null && userRanList.size() >0 ){
//					headBmList = getBmlist(userRanList);
//					for (RondomUser rondomUser : userRanList) {
//						MyLog.info(getClass(), "好友用户：" + rondomUser.getPassport());
//						getPicinfolist(rondomUser.getPassport());
//						//获取用户图片
//					} ad
					adapterTest.setDataUserSetChange(user);
						MyLog.info(getClass(), "好友用户：" + user.getPassport());
						getPicinfolist(user.getPassport()); 
						if (dialog_1 != null && dialog_1.isShowing())
							dialog_1.dismiss();
//					}
					break;
				case ROMDOMUSER_FAIL: //获取用户信息失败
					RondomUser infoFail = (RondomUser) msg.obj;
					MessageDialog.showToast(manager.getContext(), false,
							ErrorInfo.errorMap.get(infoFail.getErrCode()));
					if (dialog_1 != null && dialog_1.isShowing())
						dialog_1.dismiss();
					break;
				case ROMDOMUSER_NO: //获取用户信息失败
					MessageDialog.showToast(manager.getContext(), false,
							manager.getContext().getString(R.string.no_random_friend));
					if (dialog_1 != null && dialog_1.isShowing())
						dialog_1.dismiss();
					break;
				case PICINFOLIST_INFO:
						//下载随便看看相片
					String imageUrl = msg.obj.toString(); 
					adapterTest.setDataSetChangedImageUrl(imageUrl);
								//刷新界面
					break;
				case PICINFOLIST_INFO_FAIL:// 获取相册失败
					PicinfoList picInfo_fail = (PicinfoList)msg.obj;
					MessageDialog.showToast(manager.getContext(), false,ErrorInfo.errorMap.get(picInfo_fail.getErrCode()));
					break;
				case PICINFOLIST_RE_MYPTO_IMAGE:
					//做图片显示操作
//					Bitmap bm = (Bitmap)msg.obj;
//					//刷新界面
//					adapterTest.notifyDataSetChanged();
//					casualListView.setAdapter(adapterTest);
					break;
				case PICINFOLIST_DOWN_IMAGE_FAIL://下载图片失败
					MessageDialog.showToast(manager.getContext(), false, manager.getContext().getString(R.string.imagedown_doing_fail));
					break;
				case ADD_FRIENDS://添加好友成功
					MessageDialog.showToast(manager.getContext(), false, manager.getContext().getString(R.string.add_friend));
					break;
				case ADD_FRIENDS_FAIL://添加好友失败
					MessageDialog.showToast(manager.getContext(), false, manager.getContext().getString(R.string.add_friend_fail));
					break;
				case TIME_OUT://超时
					if (dialog_1 != null && dialog_1.isShowing())
						dialog_1.dismiss();
					MessageDialog.showToast(manager.getContext(), false, manager.getContext().getString(R.string.int_timeout));
					break;
				case INTENT_ERROR://网络错误
					if (dialog_1 != null && dialog_1.isShowing())
						dialog_1.dismiss();
					MessageDialog.showToast(manager.getContext(), false, manager.getContext().getString(R.string.int_error));
					break;
					}
			} catch (Exception e) {
			    e.printStackTrace();
			}
			}
	};
	public Bitmap getBitmap(RondomUser info ){
				Bitmap bm =null;
				MyLog.info(getClass(), "随便看看头像名字："+info.getHead_path());
					bm=	CommonUtil.loadBitMap(ctx, Config.TyDownHttp+CommonUtil.getHeadImage(info.getPassport(),
							info.getHead_path()));//下载头像
					MyLog.info(getClass(), "随便看看头像："+bm);
				if(bm == null){
				InputStream is = manager
						.getContext()
						.getResources()
						.openRawResource(
								R.drawable.inithead);
				bm = BitmapFactory.decodeStream(is);
				}
			
		return bm;
	}
    public class ViewHolder{
    	 ImageView userHead;
			TextView userName;
			TextView time;
			ImageView lookpto;
			ImageView addfriend;
			GridView gridView;
			LinearLayout Layout;
			LinearLayout imageLayout;	
			LinearLayout layout_center;
    }
	 public class ListAdapter extends BaseAdapter{
		
		 	private String imageUrl= "http://img2.vipshop.com/upload/merchandise/4787/ANTA-1033383-2-5.jpg";
	    	private Context mContext;
	        private AsyncImageLoader asyncImageLoader; 
	        private Bitmap headbm;
	        

	    	private List<RondomUser> userRanList = new ArrayList<RondomUser>();
	    	private List<String> imagelist = new ArrayList<String>();
	    	private List<Bitmap> headBmList =new ArrayList<Bitmap>(); 
	    	private ListAdapter(Context context){
	    		mContext = context; 
	    	}
		@Override
		public View getView(final int position, View convertView, ViewGroup parent) {
			Log.i(TAG, "ListAdapter getView():"+position);
			final ViewHolder holder;  
			if (convertView == null) {
				holder = new ViewHolder();  
				LayoutInflater inflater  = LayoutInflater.from(mContext); 
				convertView = inflater.inflate(R.layout.casual_image_list, null);
				holder.Layout = (LinearLayout) convertView .findViewById(R.id.LinearLayout_list);
				holder.userHead = (ImageView) convertView .findViewById(R.id.image_head);
				holder.userName = (TextView) convertView .findViewById(R.id.user_name);
				holder.time = (TextView) convertView .findViewById(R.id.user_time);
				holder.lookpto = (ImageView) convertView .findViewById(R.id.lookpto);
				holder.addfriend = (ImageView) convertView .findViewById(R.id.addfriend);
				holder.layout_center =(LinearLayout)convertView .findViewById(R.id.layout_center); 
				holder.gridView = (GridView)convertView.findViewById(R.id.gridView);
				holder.gridView.setGravity(Gravity.CENTER);// 位置居中  
				convertView.setTag(holder); 
			}else{
				holder = (ViewHolder) convertView.getTag();
			}

//			List<String> imageList =new ArrayList<String>();
//			for(int i=0;i<4;i++){
//				imageList.add(imageUrl);
//			}
			try {
				MyImageAdapter adapter = new MyImageAdapter(mContext, imagelist);
				holder.gridView.setAdapter(adapter); 
			} catch (Exception e) {
				return null;
				// TODO: handle exception
			}catch(OutOfMemoryError er){
				return null;
			}
			
			//长按操作
			holder.userHead.setOnLongClickListener(new View.OnLongClickListener() {
					
				@Override
				public boolean onLongClick(View v) { 
					MyLog.debug(getClass(), "onLongClick...");
					holder.layout_center.setVisibility(View.VISIBLE);
					return true;
				}
			});
			holder.userName.setOnLongClickListener(new View.OnLongClickListener() {
				@Override
				public boolean onLongClick(View v) {
					holder.layout_center.setVisibility(View.VISIBLE);
					return true;
				}
			});
			holder.Layout.setOnClickListener(new View.OnClickListener() {
					
					@Override
					public void onClick(View v) {
						Log.i(TAG, "单击消失");
						if(holder.layout_center.getVisibility()==View.VISIBLE)
							holder.layout_center.setVisibility(View.GONE); 
					}
				});
				//点击添加好友
			holder.addfriend.setOnClickListener(new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						//调用添加好友
					if (CommonUtil.isUserLogin(ctx)) {

						// TODO Auto-generated method stub
						// 删除操作
						new AlertDialog.Builder(ctx)
						        .setTitle(R.string.label_t)
								.setMessage(R.string.add_msg)
								.setPositiveButton(R.string.label_ok,
										new DialogInterface.OnClickListener() {
											public void onClick(
													DialogInterface dialoginterface,
													int i) {
												Log.i(TAG, "确定添加关系");
												try {
													MyLog.info(getClass(), "addfriend:"+userRanList.get(position).getPassport());
													addFriend(userRanList.get(position).getPassport());
												} catch (Exception e) {
													e.printStackTrace();
												}
												// 按钮事件
											}
										})
								.setNegativeButton(R.string.label_cancel,
										new DialogInterface.OnClickListener() {
											public void onClick(DialogInterface dialog,
													int whichButton) {
												// 取消按钮事件
												Log.i(TAG, "取消解除关系");
											}
										}).show();
					} else {
						try {
							manager.activePage(UserLoginView.class, null);
						} catch (Exception e) {
							e.printStackTrace();
						}
					}
					}
				});
				//点击查看相片
			holder.lookpto.setOnClickListener(new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						try {
							manager.activePage(PicinfoView.class, null);
						} catch (Exception e) {
							e.printStackTrace();
						}
					}
				});
				
				//设置头像
			if (headBmList != null && headBmList.size() > 0) {
				Bitmap bm = headBmList.get(position);
				bm = Bitmap.createScaledBitmap(bm, 40, 40, true);// 预先缩放，避免实时缩放，可以提高更新率
				holder.userHead.setImageBitmap(bm);
			}
			
//			InputStream is = manager
//			.getContext()
//			.getResources()
//			.openRawResource(
//					R.drawable.inithead);
//	Bitmap bm = BitmapFactory.decodeStream(is);
//	holder.userHead.setImageBitmap(bm);
				//设置昵称
			    if (userRanList != null && userRanList.size() > 0){
			    String nick = userRanList.get(position).getNick();
				if(nick!=null &&! "".equals(nick))
					holder.userName.setText(userRanList.get(position).getNick());
			    }else{
			    	String username = userRanList.get(position).getPassport();
			    	if(!"pconline".equals(username))
			    	holder.userName.setText(userRanList.get(position).getPassport().substring(0,7)+"****");
			    	else
			    		holder.userName.setText(userRanList.get(position).getPassport());
			    }
				//设置时间
					holder.time.setText("9月1日");
				MyLog.info(getClass(), "position:"+position);
				//设置四张相片
			return convertView;
		} 
		public void setDataSetChangedBitmap(Bitmap bitmap){ 
			headBmList.add(bitmap);
	    	notifyDataSetChanged();
	    }
		public void setDataSetChangedImageUrl(String imageUrl){ 
			imagelist.add(imageUrl);
	    	notifyDataSetChanged();
	    }
		public void setDataUserSetChange(RondomUser user){ 
			userRanList.add(user);
	    	notifyDataSetChanged();
	    }
		@Override
		public int getCount() {
			return (userRanList !=null && userRanList.size()>0) ? userRanList.size():0;  
		}
		@Override
		public Object getItem(int position) {
			return (userRanList !=null && userRanList.size()>0) ? userRanList.get(position): null; 
		}
		@Override
		public long getItemId(int position) {
			return position;
		}
		
	}
//	 
//	 private List<Bitmap> bmlist = new ArrayList<Bitmap>();
//	 class loadingImageFolder extends AsyncTask<Integer,Bitmap,Integer>{ 
//	 	private List<RondomUser> userRanList;
//	 		public loadingImageFolder(List<RondomUser> userRanList){
//	 			this.userRanList= userRanList;
//	 		}
//	 		@Override
//	 		protected Integer doInBackground(Integer... params) {
//	 			// TODO Auto-generated method stub
//	 			try {
//	 				bmlist.clear();
//	 				for (RondomUser info : userRanList) {
//	 					Bitmap bm =null;
//	 					MyLog.info(getClass(), "随便看看头像名字："+info.getHead_path());
//	 						bm=	CommonUtil.loadBitMap(ctx, Config.TyDownHttp+CommonUtil.getHeadImage(info.getPassport(),
//	 								info.getHead_path()));//下载头像
//	 						MyLog.info(getClass(), "随便看看头像："+bm);
//	 					if(bm == null){
//	 						InputStream is = manager.getContext().getResources().openRawResource(R.drawable.inithead);
//	 						bm = BitmapFactory.decodeStream(is);
//	 						bm = Bitmap.createScaledBitmap(bm, 48, 48,true);// 预先缩放，避免实时缩放，可以提高更新率
//	 						bm = CommonUtil.getRoundedCornerBitmap(bm);
//	 					}else{
//	 						bm = Bitmap.createScaledBitmap(bm, 48, 48,true);// 预先缩放，避免实时缩放，可以提高更新率
//	 						bm = CommonUtil.getRoundedCornerBitmap(bm);
//	 					}
//	 					this.publishProgress(bm);
//	 					bmlist.add(bm);
//	 				}
//	 			} catch (OutOfMemoryError e) {
//	 				e.printStackTrace();
//	 				return 1;
//	 			}
//	 			return 0;
//	 		}
//	 		
//	 		@Override
//	 		protected void onProgressUpdate(Bitmap... values) {
//	 			// TODO Auto-generated method stub 
//	 			if(values!=null){
//	 				MyLog.debug(getClass(), "values:"+values[0]);
//	 			}
//	 		}
//	 		@Override  
//	 	    protected void onCancelled() {  
//	 			super.onCancelled();  
//	 	    }  
//	 		 
//	 		@Override
//	 		protected void onPostExecute(Integer result) {
//	 			// TODO Auto-generated method stub 
//	 			if(result==0){ 
//	 			}
//	 		}
//	 	}
}
